

project , original("inflationrate_from1751.txt")
project , uses("constituency_elections.dta")



	***** Formula development: Coefficients

	insheet using "inflationrate_from1751.txt", clear
	drop cpi_multiplier
	replace inflationrate = subinstr(inflationrate, "%", "", .)
	destring inflationrate, replace
	gen cpi_multiplier = 1 if _n==1
	replace cpi_multiplier = (1+inflationrate/100)*cpi_multiplier[_n-1] if _n>1
		
	drop if year<1885 | year>2019
	gen a = .
	replace a = 350 if year>=1885 & year<1918
	replace a = 0 if year>=1918 & year<=1948
	replace a = 450 if year>=1949 & year<=1968
	replace a = 750 if year>=1969 & year<=1973
	replace a = 1075 if year>=1974 & year<=1977
	replace a =1750  if year>=1978 & year<=1981
	replace a = 2700 if year>=1982 & year<=1986
	replace a =3370  if year>=1987 & year<=1991
	replace a = 4430 if year>=1992 & year<=1996
	replace a = 4965 if year>=1997 & year<=2000
	replace a = 5483 if year>=2001 & year<=2004
	replace a =7150  if year>= 2005 & year<=2010
	replace a =8700  if year>= 2011 & year<=2019

	gen b = .
	replace b =.03 if year>=1885 & year<1918
	replace b =.0208  if year>=1918 & year<=1948
	replace b =.0063  if year>=1949 & year<=1968
	replace b =.0063 if year>=1969 & year<=1973
	replace b =.0075 if year>=1974 & year<=1977
	replace b =.015  if year>=1978 & year<=1981
	replace b =.023  if year>=1982 & year<=1986
	replace b =.029  if year>=1987 & year<=1991
	replace b =.037  if year>=1992 & year<=1996
	replace b =.042  if year>=1997 & year<=2000
	replace b =.046  if year>=2001 & year<=2004
	replace b =.05  if year>= 2005 & year<=2010
	replace b =.06  if year>= 2011 & year<=2017
	
	gen c = .
	replace c =300 if year>=1885 & year<1918
	replace c =0 if year>=1918
	
	gen d = .
	replace d =.03 if year>=1885 & year<1918
	replace d =.0083  if year>=1918 & year<=1928
	replace d =.0042  if year>=1929 & year<=1948
	replace d =.0021  if year>=1949 & year<=1968
	replace d =.0021 if year>=1969 & year<=1973
	replace d =.0025 if year>=1974 & year<=1977
	replace d =.005  if year>=1978 & year<=1981
	replace d =.008  if year>=1982 & year<=1986
	replace d =.009  if year>=1987 & year<=1991
	replace d =.012  if year>=1992 & year<=1996
	replace d =.014  if year>=1997 & year<=2000
	replace d =.016  if year>=2001 & year<=2004
	replace d =.02  if year>= 2005 & year<=2010
	replace d =.03  if year>= 2011 & year<=2017
	
	gen period = .
	replace period =1917 if year>=1885 & year<1918
	replace period =1928  if year>=1918 & year<=1928
	replace period =1948  if year>=1929 & year<=1948
	replace period =1968  if year>=1949 & year<=1968
	replace period =1973 if year>=1969 & year<=1973
	replace period =1977 if year>=1974 & year<=1977
	replace period =1981  if year>=1978 & year<=1981
	replace period =1986  if year>=1982 & year<=1986
	replace period =1991  if year>=1987 & year<=1991
	replace period =1996  if year>=1992 & year<=1996
	replace period =2000  if year>=1997 & year<=2000
	replace period =2004  if year>=2001 & year<=2004
	replace period =2010  if year>= 2005 & year<=2010	
	replace period =2017  if year>= 2011 & year<=2017
	
	replace a = cpi*a	
	replace b = cpi*b
	replace c = cpi*c
	replace d = cpi*d
	
	sort period year
	by period: gen a_first = a if _n==1
	by period: gen b_first = b if _n==1 
	by period: gen c_first = c if _n==1 
	by period: gen d_first = d if _n==1 
	
	bys period: egen a_adj = max(a_first)
	bys period: egen c_adj = max(c_)
	bys period: egen d_adj = max(d_)
	replace period = 1948 if period==1928
	bys period: egen b_adj = max(b_)

	
	format a_adj c_adj  %9.0fc

	replace a_adj = a_adj/1000
	replace c_adj = c_adj / 1000
	
	twoway (line b_adj year, lwidth(thick) ) (line d_adj year, lpattern(dash) lwidth(thick) ) ,  tlabel( 1885 (10) 2015, labsize(vlarge) angle(45) ) ylabel(0 (.5) 4 , labsize(vlarge) )  title("Per Elector Coefficients: b{subscript:t} and d{subscript:t}", size(vlarge)) legend( label(1 "b{subscript:t} (rate per elector, all constituencies)") label(2 "d{subscript:t} (extra rate per elector, counties only)") ring(1) position(6) size(large) ) ttitle("")   ytitle("Per Elector Rate, £", size(large)) saving( ./figures/per_elector.gph, replace) scale(1.25)
	
	twoway (line a_adj year, lwidth(thick)) (line c_adj year, lpattern(dash) lwidth(thick) ) , tlabel( 1885 (10) 2015, labsize(vlarge) angle(45) ) ylabel(0 (10) 50, labsize(vlarge)) title("Lump Sum Coefficients: a{subscript:t} and c{subscript:t}", size(vlarge)) legend( label(1 "a{subscript:t} (lump sum, all constituencies)") label(2 "c{subscript:t} (extra lump sum, counties only)") ring(1) position(6) size(large) ) ttitle("") ytitle("Lump Sum Amount, £1000s", size(large)) saving( ./figures/lumpsum.gph, replace) scale(1.25)


	
	graph combine  "./figures/lumpsum.gph"  "./figures/per_elector.gph" , xsize(20) ysize(7)  col(2) 
	graph export ./figures/coefficients_development.pdf, replace
	project , creates("figures/coefficients_development.pdf")	
	
	
	
	
	*Development in Electors and Spending Limit

	use "candidate_elections.dta", clear
	drop if by_election==1
	drop if county==.
	replace electors = electors/1000
	replace spending_limit_predicted_adj = 10*spending_limit_predicted_adj
	collapse (mean) electors spending_limit_predicted_adj candidates ,by(const year date county) // first collapse down to constituency in a given election
	collapse  (median) electors (mean) spending_limit_predicted_adj candidates ,by(year county) // then collapse by year and constituency type

	format spending_limit_predicted_adj electors %9.0fc

	twoway ( connected spending_limit_predicted_adj year if county==1, lwidth(thick) ) || (connected spending_limit_predicted_adj year if county==0, lwidth(thick)) , ///
	 tlabel( 1885 (10) 2015, labsize(vlarge) angle(45) ) ttitle(" ")	 ytitle("Spending Limit, £1000s", size(vlarge)) ylabel(0 (25) 175, labsize(vlarge)) ///
	 title("Median Spending Limit" , size(vlarge)) legend( label(1 county) label(2 borough)  ring(0) position(1) size(large) col(1) ) 	saving( ./figures/limit.gph, replace) scale(1.25)

	twoway ( connected electors year if county==1 ,lwidth(thick) ) (connected electors year if county==0 ,lwidth(thick) )  , ///
		  tlabel( 1885 (10) 2015, labsize(vlarge) angle(45) ) ttitle(" ") ytitle("# Electors, 1000s", size(vlarge)) ylabel(0 (10) 80, labsize(vlarge)) title("Median # Electors" , size(vlarge)) ///
			legend( order(1 "county" 2 "borough")  ring(0) position(5) size(large)  col(1) ) 	saving( ./figures/electors.gph, replace) scale(1.25) 

	graph combine    "./figures/limit.gph" "./figures/electors.gph" , xsize(20) ysize(7)  col(2) imargin(zero)
	 	 
	 
	graph export ./figures/limit_and_electors_development.pdf, replace
	project , creates("figures/limit_and_electors_development.pdf")	
	
	 
	
